package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.SubOption;

@Repository
public interface SubOptionDao extends JpaRepository<SubOption, Integer>, JpaSpecificationExecutor<SubOption> {

	@Query("from SubOption where content = ?1")
	List<SubOption> find(String name);

	@Query("from SubOption where content like ?1")
	List<SubOption> findLike(String name);

	@Query(value = "select * from SubOption limit ?, ?", nativeQuery = true)
	List<SubOption> findPage(Integer offset, Integer size);

	@Query(value = "select * from SubOption where content = ? limit ?, ?", nativeQuery = true)
	List<SubOption> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from SubOption where content like ? limit ?, ?", nativeQuery = true)
	List<SubOption> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from SubOption where content = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from SubOption where content like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from SubOption order by id asc")
	List<SubOption> findAllAsc();

	List<SubOption> findSubOptionsBySubjectHubId(Integer subjectHubId);
}

